﻿using QModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace QServices.Services
{
	public class QTimerStatusService : QMainService
	{
		public bool AddOrUpdate(QTimerStatus info)
		{

			var db = CreateDbContext();
			if (string.IsNullOrWhiteSpace(info.ID))
			{
				info.ID = Guid.NewGuid().ToString();
				db.Set<QTimerStatus>().Add(info);
			}
			else
			{
				var exit = db.Set<QTimerStatus>().FirstOrDefault(x => x.ID == info.ID);
				if (exit != null)
				{
					exit.IsLogger = info.IsLogger;
					exit.MinuteBeforeFeed = info.MinuteBeforeFeed;

					exit.IsTimer_PLC = info.IsTimer_PLC;
					exit.Interval_Timer_PLC = info.Interval_Timer_PLC;

					exit.IsTimer_JieMian = info.IsTimer_JieMian;
					exit.Interval_Timer_JieMian = info.Interval_Timer_JieMian;

					exit.IsTimer_HuanKong = info.IsTimer_HuanKong;
					exit.Interval_Timer_HuanKong = info.Interval_Timer_HuanKong;

				}				
			}
			db.SaveChanges();



			return true;
		}
		public QTimerStatus GetQTimerStatus(string carNumber)
		{
			var db = CreateDbContext();
			var info = db.Set<QTimerStatus>().FirstOrDefault(x => x.CarNumber == carNumber);
			return info;
		}
	}
}
